#include "PrecompiledHeaderRenderer_OpenGL.h"
#include "BlendWrapper.h"

/*--------------------------------------------------------------------------*/
GLboolean BlendWrapper::_BlendEnabled = GL_FALSE;
GLenum BlendWrapper::_BlendFuncSrc = GL_SRC_ALPHA;
GLenum BlendWrapper::_BlendFuncDst = GL_ONE_MINUS_SRC_ALPHA;
/*--------------------------------------------------------------------------*/

BlendWrapper::BlendWrapper()
{
	if (_BlendEnabled)
	{
		glEnable(GL_BLEND);
	}
	else
	{
		glDisable(GL_BLEND);
	}

	glBlendFunc(_BlendFuncSrc, _BlendFuncDst);
}

/*--------------------------------------------------------------------------*/

BlendWrapper::~BlendWrapper()
{
}

/*--------------------------------------------------------------------------*/

void BlendWrapper::BlendEnabled(GLboolean v1)
{
	if (v1 != _BlendEnabled)
	{
		_BlendEnabled = v1;

		if (v1)
		{
			glEnable(GL_BLEND);
		}
		else
		{
			glDisable(GL_BLEND);
		}
	}
}

/*--------------------------------------------------------------------------*/

void BlendWrapper::BlendFunc(GLenum src, GLenum dst)
{
	bool changed = false;

	if (src != _BlendFuncSrc)
	{
		_BlendFuncSrc = src;
		changed = true;
	}

	if (dst != _BlendFuncDst)
	{
		_BlendFuncDst = dst;
		changed = true;
	}

	if (changed)
	{
		glBlendFunc(_BlendFuncSrc, _BlendFuncDst);
	}
}

/*--------------------------------------------------------------------------*/